import Vue from 'vue'
import Vuex from 'vuex'
import { setItem, getItem, delItem } from '@/utils/storage.js'

Vue.use(Vuex)
const TOKEN_KEY = 'token'
export default new Vuex.Store({
  state: {
    user: getItem(TOKEN_KEY)
  },
  mutations: {
    setUser(state, value) {
      state.user = value
      setItem(TOKEN_KEY, value)
    },
    delUser(state) {
      state.user = null
      delItem(TOKEN_KEY)
    }
  },
  actions: {
  },
  modules: {
  }
})
